package com.loanly.view;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Map;

import org.hibernate.HibernateException;
import org.hibernate.Query;
import org.hibernate.Session;

import com.loanly.controller.SummaryManager;
import com.loanly.util.HibernateUtil;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
 
 
public class SummaryAction extends ActionSupport {
 
    /**
	 * 
	 */
	private static final long serialVersionUID = -2325759296649094711L;
    private String user_name;
    private SummaryManager summaryManager;
    private Double sumAmount;
    private Double dueAmount;
    private Double assetAmount;
    private Double debitAmount;
    private Double netAmount;
    private Double curr_month_in;
    private Double curr_month_interest;
    private Double curr_month_award;
    private Double total_in;
    private Double total_interest;
    private Double total_award;

	private String next1_month;
	private String next2_month;
	private String next3_month;
	private String curr_month;
    
	private Double next1_month_amt;
	private Double next2_month_amt;
	private Double next3_month_amt;

    public SummaryAction() {
    	summaryManager = new SummaryManager();
    	setSumAmount(0d);
    	setDueAmount(0d);
    	setAssetAmount(0d);
    	setDebitAmount(0d);
    	setNetAmount(0d);
    	setCurr_month_in(0d);
    	setCurr_month_interest(0d);
    	setCurr_month_award(0d);
    	setTotal_in(0d);
    	setTotal_interest(0d);
    	setTotal_award(0d);

    	SimpleDateFormat df = new SimpleDateFormat("YYYYMM");
    	Date now = new Date();
    	Calendar   cal=Calendar.getInstance();
    	curr_month = df.format(cal.getTime());
    	cal.add(Calendar.MONTH,1);
    	next1_month = df.format(cal.getTime());
    	cal.add(Calendar.MONTH,1);
    	next2_month = df.format(cal.getTime());
    	cal.add(Calendar.MONTH,1);
    	next3_month = df.format(cal.getTime());
    	
    }
 
    public String execute() {

    	setSumAmount (summaryManager.getSumAmount());
        //
    	setDueAmount(summaryManager.getDueAmount());
    	setAssetAmount(summaryManager.getAssetAmount());
    	setDebitAmount(summaryManager.getDebitAmount());
    	
    	setCurr_month_interest(summaryManager.getCurr_Month_Interest());
    	setCurr_month_award(summaryManager.getCurr_Month_Award());
    	setCurr_month_in(summaryManager.getCurr_Month_Interest() + summaryManager.getCurr_Month_Award());

    	setTotal_interest(summaryManager.getTotal_Interest());
    	setTotal_award(summaryManager.getTotal_Award());
    	setTotal_in(summaryManager.getTotal_Interest() + summaryManager.getTotal_Award());
        //netamount = 净资产
        setNetAmount(this.getAssetAmount() - this.getDebitAmount());
        setNext1_month_amt(summaryManager.getMonth_amt(next1_month));
        setNext2_month_amt(summaryManager.getMonth_amt(next2_month));
        setNext3_month_amt(summaryManager.getMonth_amt(next3_month));
        
        //curr_month_interest = 当月利息
        
        //curr_month_award = 当月奖励

        //curr_month_in = 当月收益
        
        //total_in = 总收益
        
        //total_interest = 总利息
        
        //total_award = 总奖励
        
        System.out.println("SummaryAction execute called");
        return SUCCESS;
    }
 

	public Double getSumAmount() {
		return sumAmount;
	}

	public void setSumAmount(Double sumAmount) {
		this.sumAmount = sumAmount;
	}

	public Double getNetAmount() {
		return netAmount;
	}

	public void setNetAmount(Double netAmount) {
		this.netAmount = netAmount;
	}

	public Double getCurr_month_in() {
		return curr_month_in;
	}

	public void setCurr_month_in(Double curr_month_in) {
		this.curr_month_in = curr_month_in;
	}

	public Double getCurr_month_interest() {
		return curr_month_interest;
	}

	public void setCurr_month_interest(Double curr_month_interest) {
		this.curr_month_interest = curr_month_interest;
	}

	public Double getCurr_month_award() {
		return curr_month_award;
	}

	public void setCurr_month_award(Double curr_month_award) {
		this.curr_month_award = curr_month_award;
	}

	public Double getTotal_in() {
		return total_in;
	}

	public void setTotal_in(Double total_in) {
		this.total_in = total_in;
	}

	public Double getTotal_interest() {
		return total_interest;
	}

	public void setTotal_interest(Double total_interest) {
		this.total_interest = total_interest;
	}

	public Double getTotal_award() {
		return total_award;
	}

	public void setTotal_award(Double total_award) {
		this.total_award = total_award;
	}

	public Double getDueAmount() {
		return dueAmount;
	}

	public void setDueAmount(Double dueAmount) {
		this.dueAmount = dueAmount;
	}

	public Double getAssetAmount() {
		return assetAmount;
	}

	public void setAssetAmount(Double assetAmount) {
		this.assetAmount = assetAmount;
	}

	public String getUser_name() {
		return user_name;
	}

	public void setUser_name(String user_name) {
		this.user_name = user_name;
	}

	public Double getDebitAmount() {
		return debitAmount;
	}

	public void setDebitAmount(Double debitAmount) {
		this.debitAmount = debitAmount;
	}

	public String getNext1_month() {
		return next1_month;
	}

	public void setNext1_month(String next1_month) {
		this.next1_month = next1_month;
	}

	public String getNext2_month() {
		return next2_month;
	}

	public void setNext2_month(String next2_month) {
		this.next2_month = next2_month;
	}

	public String getNext3_month() {
		return next3_month;
	}

	public void setNext3_month(String next3_month) {
		this.next3_month = next3_month;
	}

	public Double getNext1_month_amt() {
		return next1_month_amt;
	}

	public void setNext1_month_amt(Double next1_month_amt) {
		this.next1_month_amt = next1_month_amt;
	}

	public Double getNext3_month_amt() {
		return next3_month_amt;
	}

	public void setNext3_month_amt(Double next3_month_amt) {
		this.next3_month_amt = next3_month_amt;
	}

	public Double getNext2_month_amt() {
		return next2_month_amt;
	}

	public void setNext2_month_amt(Double next2_month_amt) {
		this.next2_month_amt = next2_month_amt;
	}
}